package com.wx.mall.goods.mapper;

import com.wx.mall.goods.entity.Album;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author j
 * @since 2020-03-15
 */
public interface AlbumMapper extends BaseMapper<Album> {

    @Select({"<script>\n"+
            " SELECT\n" +
            "        *\n" +
            "        FROM\n" +
            "        pro_album\n" +
            "        where 1=1\n" +
            "        <if test=\"id!='' and id!=null\">\n" +
            "            and id = #{id}\n" +
            "        </if>\n" +
            "        <if test=\"title!='' and title!=null\">\n" +
            "            and title like concat('%',#{title},'%')\n" +
            "        </if>\n" +
            "        <if test=\"imageItems!='' and imageItems!=null\">\n" +
            "            and image_items like concat('%',#{imageItems},'%')\n" +
            "        </if>\n" +
            "        order by sort desc\n" +
            "</script>"})
    @Results({@Result(property = "addTime", column = "add_time"),@Result(property = "imageItems", column = "image_items"),@Result(property = "imageNum", column = "image_num")})
    List<Album> find(Album album);

    @Delete("delete from pro_album where id=#{id}")
    @Results({@Result(property = "addTime", column = "add_time"),@Result(property = "imageItems", column = "image_items"),@Result(property = "imageNum", column = "image_num")})
    Integer remove(Integer id);

    @Insert("insert into pro_album(title,image,image_items,sort,instruction,image_num,add_time) values(#{title},#{image},#{imageItems},#{sort},#{instruction},#{imageNum},#{addTime})")
    @Results({@Result(property = "addTime", column = "add_time"),@Result(property = "imageItems", column = "image_items"),@Result(property = "imageNum", column = "image_num")})
    void save(Album album);

    @Update("update pro_album set title=#{title}, image=#{image}, image_items=#{imageItems}, sort=#{sort}, instruction=#{instruction}, image_num=#{imageNum} where id=#{id}")
    @Results({@Result(property = "addTime", column = "add_time"),@Result(property = "imageItems", column = "image_items"),@Result(property = "imageNum", column = "image_num")})
    void updateData(Album album);
}
